package com.frcdi.qms.web.controller.measurement;

import com.frcdi.qms.common.core.controller.BaseController;
import com.frcdi.qms.common.core.domain.AjaxResult;
import com.frcdi.qms.common.core.page.TableDataInfo;
import com.frcdi.qms.common.utils.poi.ExcelUtil;
import com.frcdi.qms.measurement.domain.MeasurementBalance;
import com.frcdi.qms.measurement.service.IMeasurementBalanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 一般性测量(天平)Controller
 *
 * @author cell
 * @date 2024-02-26
 */
@Api(tags = "一般性测量(天平)")
@RestController
@RequestMapping("/measurement/balance")
public class MeasurementBalanceController extends BaseController
{
    @Autowired
    private IMeasurementBalanceService measurementBalanceService;

    /**
     * 查询一般性测量(天平)列表
     */
    @ApiOperation("查询一般性测量(天平)列表")
    @PreAuthorize("@ss.hasPermi('measurement:balance:list')")
    @GetMapping("/list")
    public TableDataInfo list(MeasurementBalance measurementBalance)
    {
        startPage();
        List<MeasurementBalance> list = measurementBalanceService.selectMeasurementBalanceList(measurementBalance);
        return getDataTable(list);
    }

    /**
     * 导出一般性测量(天平)列表
     */
    @ApiOperation("导出一般性测量(天平)列表")
    @PreAuthorize("@ss.hasPermi('measurement:balance:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MeasurementBalance measurementBalance)
    {
        List<MeasurementBalance> list = measurementBalanceService.selectMeasurementBalanceList(measurementBalance);
        ExcelUtil<MeasurementBalance> util = new ExcelUtil<MeasurementBalance>(MeasurementBalance.class);
        util.exportExcel(response, list, "一般性测量(天平)数据");
    }

    /**
     * 获取一般性测量(天平)详细信息
     */
    @ApiOperation("获取一般性测量(天平)详细信息")
    @PreAuthorize("@ss.hasPermi('measurement:balance:query')")
    @GetMapping(value = "/{measurementId}")
    public AjaxResult getInfo(@PathVariable("measurementId") Long measurementId)
    {
        return success(measurementBalanceService.selectMeasurementBalanceByMeasurementId(measurementId));
    }

    /**
     * 新增一般性测量(天平)
     */
    @ApiOperation("新增一般性测量(天平)")
    @PreAuthorize("@ss.hasPermi('measurement:balance:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MeasurementBalance measurementBalance)
    {
        measurementBalance.setCreateBy(getUsername());
        return success(measurementBalanceService.insertMeasurementBalance(measurementBalance));
    }

    /**
     * 修改一般性测量(天平)
     */
    @ApiOperation("修改一般性测量(天平)")
    @PreAuthorize("@ss.hasPermi('measurement:balance:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MeasurementBalance measurementBalance)
    {
        measurementBalance.setUpdateBy(getUsername());
        return toAjax(measurementBalanceService.updateMeasurementBalance(measurementBalance));
    }

    /**
     * 删除一般性测量(天平)
     */
    @ApiOperation("删除一般性测量(天平)")
    @PreAuthorize("@ss.hasPermi('measurement:balance:remove')")
	@DeleteMapping("/{measurementIds}")
    public AjaxResult remove(@PathVariable Long[] measurementIds)
    {
        return toAjax(measurementBalanceService.deleteMeasurementBalanceByMeasurementIds(measurementIds));
    }

    /**
     * 获取编码
     */
    @ApiOperation("获取编码")
    @PreAuthorize("@ss.hasPermi('measurement:balance:add')")
    @GetMapping("/getCode")
    public AjaxResult getcode(){
        return success(measurementBalanceService.getCode());
    }
}
